#include <iostream>

using namespace std;

const int N = 1e5 + 10;

int n;
int ne[N], pre[N], h;
bool st[N];

int main()
{
	cin >> n;
	//初始化
	pre[1] = h;
	ne[h] = 1;

	for(int i = 2; i <= n; i++)
	{
		int k, p; cin >> k >> p;
		if(p == 0)
		{
			//把i插入到k的左边
			pre[i] = pre[k];
			ne[i] = k;
			ne[pre[k]] = i;
			pre[k] = i;
		}
		else 
		{
			//把i插入到k的右边
			pre[i] = k;
			ne[i] = ne[k];
			pre[ne[k]] = i;
			ne[k] = i;
		}

	}

	int m; 
	cin >> m;
	while(m--)
	{
		int x; cin >> x;
		//将x删除
		if(st[x] == true) continue;
		
		ne[pre[x]] = ne[x];
		pre[ne[x]] = pre[x];
		st[x] = true; // 标记 x 已经被删除
	}

	//打印
	for(int i = ne[h]; i; i = ne[i])
	{
		cout << i << " ";
	}


	return 0;
}






